/**
 * 描述: 服务内容列表页
 *
 * @author guoqiao
 * @since 2021/11/17 14:19
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-149',
        defaultToolbar: ['filter']
    });
    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    let ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.acceId);
    });

    // 启用停用 / 新增  toolbar
    table.on("toolbar(zmn-table)", function (obj) {
         if (obj.event === "add") {
             let title = '新增验收项目';
             layer.open({
                 type: 2,
                 offset: '15%',
                 area: ['690px', '500px'],
                 title: [title],
                 content: ["/base/acceptproject/addEditView.action", 'no'],
                 end: function () {
                     window.location.reload();
                 }
             });
         }
         if (obj.event == "start" || obj.event == "stop") {
             if (ids.length === 0) {
                 return layer.alert("请选择至少1条数据！");
             }
             zmnPage.layStartStop(obj, "/base/acceptproject/updateStatus.action", ids.join(","));
         }
    });
    // 启用停用 checkbox
    form.on("switch(chk_one_status)", function (obj) {
        let  url = "/base/acceptproject/updateStatus.action";
        let servId = obj.elem.getAttribute("key");
        let status = obj.elem.checked ? 2 : 1;
        switch (status) {
            case 1:
                zmnPage.ajaxSimple(url, {ids: servId, status: 1}, 1000);
                break;
            case 2:
                zmnPage.ajaxSimple(url, {ids: servId, status: 2}, 1000);
                break;
        }
        setTimeout(function () {
            location.reload(true);
        }, 3000);
    });
    // 修改
    $("body").on("click", ".btn-operate", event => {
        let acceId = $(event.target).data("id");
        let title = '修改验收项目';
        layer.open({
            type: 2,
            offset: '15%',
            area: ['690px', '500px'],
            title: [title],
            content: ["/base/acceptproject/addEditView.action?acceId="+acceId, 'no'],
            end: function () {
                window.location.reload();
            }
        });
        return false;
    });
    // 排序
    table.on("edit(zmn-table)", function (obj) {
        zmnPage.laySort(obj, "/base/acceptproject/updateSort.action", obj.data.acceId);
        setTimeout(function () {
            location.reload(true);
        }, 3000);
    });
    //查询条件重置
    form.on('submit(zmn-form-reset)', function (obj) {
        form.val("zmn-acce-filter", {
            "acceIdOrName": ""
        });
        return false;
    });
    //对外暴露的接口
    exports('plat_base_acceptproject_list', {});
});
//显示描述
function show_tips(flag, tips, obj){
    //小tips
    //如果没有权限则提示
    if (!flag) {
        layer.tips(tips,obj,{
            tips:[1,'#3595CC'],
            time:3000
        })
    }
}
